package com.example.demo.study.beanLifcycle;

import org.springframework.beans.factory.config.BeanPostProcessor;

/**
 * 用来对bean的功能增强
 * SpringAOP的实现实际就借助了BeanPostProcessor
 */
public class CustomBeanPostProcessor implements BeanPostProcessor {
    @Override
    public Object postProcessBeforeInitialization(Object bean, String beanName) {
        if (bean instanceof LifeCycleBean) {
            System.out.println("BeanPostProcessor.postProcessBeforeInitialization: " + beanName);
        }
        return bean;
    }

    @Override
    public Object postProcessAfterInitialization(Object bean, String beanName) {
        if (bean instanceof LifeCycleBean) {
            System.out.println("BeanPostProcessor.postProcessAfterInitialization: " + beanName);
        }
        return bean;
    }

}
